package forum.server.controller;
import java.util.Vector;

import forum.server.domain.*;
import forum.shared.exceptions.*;

/** 
 * This Interface acts as a facade to the server logic, which is implemented
 * in 2 handlers: PostHandler, UserHandler.
 * 
 * @author Mirsky
 */
public interface ForumFacadeInt {
	/**
	 * increases the count of the online guests. 
	 * @throws DatabaseException on database error.
	 */
	public void incGuestCount() throws DatabaseException;
	/**
	 * decreases the count of the online guests. 
	 * @throws DatabaseException on database error.
	 */
	public void decGuestCount() throws DatabaseException;
	/**
     * gets the currently connected registered users.
     * @return the connected users.
     * @throws DatabaseException on database error.
     */
	public Vector<String> getOnlineUsers() throws DatabaseException;
	/**
	 * gets the online guests count.
	 * @throws DatabaseException on database error.
	 * @return the guests count.
	 */
	public int getGuestCount() throws DatabaseException;
	
	/**
	 * @return a String representation of the forum structure.
	 * @throws DataBaseException
	 */
	public String viewForum() throws DatabaseException;

	/**
	 * Registers the user in the system.
     *
	 * @param username the user-name of the user. 
	 * @param pass the password (not encrypted) of the user.
	 * @return the LoggedInUser object which encapsulates the user's private info.
	 * @throws RegistrationException in case username exists, or invalid password.
	 * @throws DatabaseException
	 */
	public LoggedInUser register(String username, String pass) 
	throws RegistrationException, DatabaseException;  

	/**
	 * Logs the user onto the system (Offline --> Online).
     *
	 * @param username the user-name of the user. 
	 * @param pass the password (not encrypted) of the user.
	 * @return the LoggedInUser object which encapsulates the user's private info.
	 * @throws IncorrectLoginException in case of incorrect login data.
	 * @throws NoSuchUserException
	 * @throws DatabaseException
	 */
	public LoggedInUser login(String username, String pass) 
	throws IncorrectLoginException, NoSuchUserException, DatabaseException;

	/**
	 * logs off the user from the system (Online --> Offline).
	 */
	public void logoff();

	/**
	 * Adds a new thread (a root post) to the forum .
     *
	 * @param header the header (perhaps topic) of the post.
	 * @param pc the contents of the post.
	 * @return the post that was added to the forum.
	 * @throws NotLoggedInException in case it's a guest user.
	 * @throws DatabaseException 
	 */
	public Post addPost(String header, PostContent pc) 
	throws NotLoggedInException, DatabaseException;

	/**
	 * Modifies an existing post in the forum.
     *
	 * @param PostId the id of the post to modify.
	 * @param pc the new content of the post which will replace the existing one.
	 * @return the updated post.
	 * @throws NotLoggedInException in case it's a guest user.
	 * @throws NoSuchPostException,
	 * @throws UnauthorizedOpException in case user don't have sufficient permissions.
	 * @throws DatabaseException 
	 */
	public Post modifyPost(int postId, PostContent pc) 
	throws NotLoggedInException, NoSuchPostException, 
	UnauthorizedOpException, DatabaseException;

    public void deletePost(int postId)
	throws NotLoggedInException, NoSuchPostException,
	UnauthorizedOpException, DatabaseException;
	/**
	 * Adds a reply to a post by creating a new post as it's child.
     *
	 * @param PostId the id of the post to reply to.
	 * @param header the header of the new post (the reply).
	 * @param pc the content of the reply post.
	 * @return the reply post that was created.
	 * @throws NotLoggedInException in case it's a guest user.
	 * @throws NoSuchPostException
	 * @throws DatabaseException
	 */
	public Post replyToPost(int postId, String header, PostContent pc) 
	throws NotLoggedInException, NoSuchPostException, DatabaseException;

	/**
	 * Promotes a certain user to a forum moderator.
     *
	 * @param username the username of the user to promote.
	 * @return the new Moderator object which encapsulates the user's private information.
	 * @throws NotLoggedInException
	 * @throws UnauthorizedOpException in case loggedInUser != Admin.
	 * @throws NoSuchUserException
	 * @throws DatabaseException
	 */
	public Moderator promoteModerator(String[] usernames) 
	throws NotLoggedInException, UnauthorizedOpException, NoSuchUserException, DatabaseException;

	/**
	 * Demotes a certain user to a regular forum user.
	 * the user must be a moderator.
     *
	 * @param username the username of the user to demote.
	 * @return the new LoggedInUser object which encapsulates the user's private information.
	 * @throws NotLoggedInException
	 * @throws UnauthorizedOpException in case loggedInUser != Admin.
	 * @throws NoSuchUserException
	 * @throws DatabaseException
	 */
	public LoggedInUser demoteModerator(String[] usernames)
	throws NotLoggedInException, UnauthorizedOpException, NoSuchUserException, DatabaseException;

	/**
     * Return an encoded view of serach hits, sorted according to score,
     * in the range [from, to].
     *
	 * @param username The username of the author who wrote the post.
	 * @param from hits from index from
	 * @param to hits until index to
	 * @return The encoded view of matching posts.
	 * @throws NoSuchUserException 
	 * @throws InvalidSearchRangeException 
	 */	
	public String searchByAuthor(String username, int from, int to)
	throws NoSuchUserException, InvalidSearchRangeException;

	/**
     * Return an encoded view of serach hits, sorted according to score,
     * in the range [from, to].
     *
	 * @param phrase The phrase which we would like to search
	 * @param from hits from index from
	 * @param to hits until index to
	 * @return The encoded view of matching posts.
	 * @throws InvalidSearchRangeException 
	 */	
	public String searchByContent(String phrase, int from, int to)
	throws InvalidSearchRangeException;
	
	/**
	 * @return all the moderators in the system.
	 * @throws DatabaseException on db error.	 
	 */
	public Vector<String> getModerators() throws DatabaseException;
	
	/**
	 * @return all the registered users.
	 * @throws DatabaseException on db error.	 
	 */
	public Vector<String> getAllRegisteredUsers() throws DatabaseException;
	
	/**
	 * 
	 * @return all the non admin, moderator in the system.
	 * @throws DatabaseException on db error.
	 */
	public Vector<String> getAllUsersForPromotion() throws DatabaseException;
	
	/**
	 * 
	 * @return connected users.
	 * @throws DatabaseException on db error.
	 */
	public Vector<String> getConnectedUsers() throws DatabaseException;
	

}
